<!-- 员工积分->列表 -->
<template>
  <div style="padding: 15px;">
    <vxe-toolbar id="warehouseLocationId" :setting="{storage: true}" export :refresh="{query: findList}">
      <template v-slot:buttons>
        <el-button @click="findList">查询</el-button>
      </template>
    </vxe-toolbar>
    <vxe-table
      ref="xTable"
      border
      resizable
      stripe
      highlight-current-row
      show-footer
      highlight-hover-row
      row-id="id"
      class="mytable-footer"
      :export-config='{type:"csv"}'
      height="700"
      :loading="loading"
      align="center"
      :data="tableData"
      :edit-config="{trigger: 'click', mode: 'row', showStatus: true}"
      sort-config.remote
      @sort-change="sortList"
      :seq-config="{startIndex: listQuery.pageNum * listQuery.pageSize - listQuery.pageSize}"
    >
      <vxe-table-column type="seq" width="60"></vxe-table-column>
      <vxe-table-column type="checkbox" width="60"></vxe-table-column>
      <vxe-table-column field="branchCode" title="所属机构" min-width="200" width="200" sortable/>
      <vxe-table-column>
        <vxe-table-column field="name" title="姓名" min-width="150" sortable/>
        <template v-slot:header="{ column }">
          <el-input v-model="listQuery.name" placeholder="员工姓名" clearable/>
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="phone" title="手机号" min-width="150" sortable/>
        <template v-slot:header="{ column }">
          <el-input v-model="listQuery.phone" placeholder="手机号" clearable/>
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="employeePoints" title="员工积分" min-width="200" sortable/>
        <template v-slot:header="{ column }">
          <el-input type="number" min="0"  v-model="listQuery.employeePointsLow" placeholder="下限" style="width:45%;"/>
          -
          <el-input type="number" min="0"  v-model="listQuery.employeePointsUp" placeholder="上限" style="width:80px;"/>
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="availablePoints" title="可用积分" min-width="200" sortable/>
        <template v-slot:header="{ column }">
            <el-input type="number" min="0"  v-model="listQuery.availablePointsLow" placeholder="下限" style="width:45%;"/>
            -
            <el-input type="number" min="0"  v-model="listQuery.availablePointsUp" placeholder="上限" style="width:80px;"/>
        </template>
      </vxe-table-column>

      <!--<vxe-table-column>
        <vxe-table-column field="gmtCreated" title="创建时间" min-width="100" sortable/>
        <template v-slot:header="{ column }">
          <el-date-picker
            v-model="listQuery.gmtCreated"
            value-format="yyyy-MM-dd HH:mm:ss"
            format="yyyy-MM-dd"
            type="date"
            style="width: 100%"
            :picker-options="pickerOptions"
            placeholder="选择日期">
          </el-date-picker>
        </template>
      </vxe-table-column>-->
      <vxe-table-column title="操作" fixed="right" min-width="100"  >
        <template slot-scope="scope">
          <el-tooltip  effect="dark" content="兑换" placement="top">
            <vxe-button type="text" @click="funcEdit(scope.row.partyCode,scope.row.availablePoints)" >
              <i class="el-icon-shopping-cart-1"/>
              <!--              <i class="el-icon-edit"/>-->
            </vxe-button>
          </el-tooltip>
        </template>
      </vxe-table-column>
    </vxe-table>
    <vxe-pager
      :loading="loading"
      :current-page.sync="listQuery.pageNum"
      :page-size.sync="listQuery.pageSize"
      :total="listQuery.total"
      :layouts="['PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump', 'Sizes', 'FullJump', 'Total']"
      @page-change="handlePageChange"
    />
    <!--    <vxe-modal v-model="modelDetailFlag" title="新增" width="500" height="350" destroy-on-close resize>-->
    <!--      <compEdit :auditEdit="compEdit" @fatherEditMethod="fatherEdit" @fatherCancelMethod="fatherCancel" :operationCode="operationCode"/>-->
    <!--    </vxe-modal>-->
    <!--    <vxe-modal v-model="modelAddFlag" title="新增" width="500" height="300" destroy-on-close resize>-->
    <!--      <compAdd ref="addRef" @fatherAddMethod="fatherAdd" />-->
    <!--    </vxe-modal>-->
    <vxe-modal v-model="modelEditFlag" title="兑换" width="500" height="400" destroy-on-close resize>
      <compEdit ref="editRef" @fatherEditMethod="fatherEdit" @fatherCancelMethod="fatherCancel" :operationCode="operationCode" :auditEdit="auditEdit" />
    </vxe-modal>
  </div>
</template>
<script>
import Vue from 'vue'
import 'xe-utils'
import VXETable from 'vxe-table'
import 'vxe-table/lib/index.css'
import XEUtils from 'xe-utils'
import VXEUtils from 'vxe-utils'
Vue.use(VXETable, VXEUtils, XEUtils, {mounts: ['cookie']})
import compEdit from './components/pointsExchange.vue'
import {employeesIntegral} from "@/api/integralManage/employeesIntegral";
import { getDepartmentList, listDict } from "@/api/store"; // 部门
import request from '@/utils/request'
export default {
  name: 'Parent',
  components: {
    compEdit
  },
  data() {
    return {
      message: '',
      loading: false,
      tableData: [],
      modelAddFlag: false,
      modelEditFlag: false,
      modelDetailFlag: false,
      gmtCreatedRange:"",
      gmtModifiedRange:"",
      copy: false,
      listQuery: {
        groupCode: '',
        departmentCode: '',
        name: '',
        phone: '',
        partyCode:'',
        employmentType: '',
        outsourcer: '',
        employeePoints:'',
        employeePointsUp: '',
        employeePointsLow: '',
        availablePoints:'',
        availablePointsUp: '',
        availablePointsLow: '',
        pageNum: 1,
        pageSize: 10,
        sortField: '',
        sortType: '',
        total: 0
      },
      operationCode:'',
      auditEdit: '',
      organization:[],
      partyGroup: [],
    }
  },
  created() {
    this.findList()
  },
  methods: {
    findList() {
      this.loading = true
      employeesIntegral(this.listQuery).then(response => {
        this.tableData = response.data.records
        this.listQuery.total = response.data.total
        this.loading = false
      })
    },
    changeDate(value, prefix) {
      if (value) {
        this.listQuery[`${prefix}Start`] = value[0] + " 00:00:00";
        this.listQuery[`${prefix}End`] = value[1] + " 23:59:59";
      } else {
        this.listQuery[`${prefix}Start`] = "";
        this.listQuery[`${prefix}End`] = "";
      }
    },
    // 排序
    sortList({column, property, order}) {
      if (order) {
        this.listQuery.sortField = property
        this.listQuery.sortType = order
      } else {
        this.listQuery.sortField = ''
      }
      this.findList()
    },
    // 兑换
    funcEdit(code, employee) {
      this.auditEdit = code
      this.operationCode = employee
      this.modelEditFlag = true
    },
    // 详情方法
    funcDetail(code) {
      this.supplyDetail = code
      this.modelDetailFlag = true
    },
    // 增加组件的父方法
    fatherAdd() {
      this.modelAddFlag = false
      this.findList()
    },
    // 编辑组件的父方法
    fatherEdit() {
      this.modelEditFlag = false
      this.findList()
    },
    // 公共取消
    fatherCancel(modelFlag) {
      switch (modelFlag) {
        case 'add':
          this.modelAddFlag = false
          break;
        case 'edit':
          this.modelEditFlag = false
          break;
        case 'detail':
          this.modelDetailFlag = false
          break;
        default:
      }
    },
    // 分页handle
    handlePageChange({currentPage, pageSize}) {
      this.listQuery.pageNum = currentPage
      this.listQuery.pageSize = pageSize
      this.findList()
    },
    // 底部颜色设置
    footerCellClassName({$rowIndex, column, columnIndex}) {
      if (columnIndex === 0) {
        if ($rowIndex === 0) {
          return 'col-blue'
        } else {
          return 'col-red'
        }
      }
    },
    // 设置底部合计
    footerMethod({columns, data}) {
      return [
        columns.map((column, columnIndex) => {
          if (columnIndex === 0) {
            return '合计'
          }
          if (['pageviews', 'forecast'].includes(column.property)) {
            return XEUtils.sum(data, column.property)
          }
          return null
        })
      ]
    }
  }
}
</script>
